import View from "../../../../mvc/View";
import {gContext} from "./vc/Main";
import Commands from "../constants/Commands";
import ViewNames from "../constants/ViewNames";

export default class HomeView extends View {

    constructor(name, viewComponent) {
        super(name, viewComponent);
    }

    getHomeVc() {
        return this.viewComponent;
    }

    onRegister() {
        let vc = this.getHomeVc();
        vc.circle.click(this.onStartGame, this);
        vc.startGame.click(this.onStartGame, this);
        vc.challengeBtn.click(this.onChallenge, this);
        vc.rankingBtn.click(this.onRanking, this);
        vc.soundSwitch.click(this.onSoundSwitch, this);
        gContext.uiContainer.addChild(vc);
    }

    onRemove() {
        let vc = this.getHomeVc();
        vc.circle.removeClick(this.onStartGame, this);
        vc.startGame.removeClick(this.onStartGame, this);
        vc.challengeBtn.removeClick(this.onChallenge, this);
        vc.rankingBtn.removeClick(this.onRanking, this);
        vc.soundSwitch.removeClick(this.onSoundSwitch, this);
        vc.dispose();
    }

    onStartGame() {
        this.sendEvent(Commands.REMOVE_VIEW, {
            name: ViewNames.HOME
        });
    }

    onChallenge() {
        this.sendEvent(Commands.REMOVE_VIEW, {
            name: ViewNames.HOME
        });
    }

    onRanking() {
        this.sendEvent(Commands.REMOVE_VIEW, {
            name: ViewNames.HOME
        });
    }

    onSoundSwitch() {

    }
}